package com.iss.examsys.entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "exam_paper")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ExamPaper.findAll", query = "SELECT e FROM ExamPaper e"),
    @NamedQuery(name = "ExamPaper.findById", query = "SELECT e FROM ExamPaper e WHERE e.id = :id"),
    @NamedQuery(name = "ExamPaper.findByName", query = "SELECT e FROM ExamPaper e WHERE e.name = :name"),
    @NamedQuery(name = "ExamPaper.findByDeprecated", query = "SELECT e FROM ExamPaper e WHERE e.deprecated = :deprecated"),
    @NamedQuery(name = "ExamPaper.findByModuleIds", query = "SELECT e FROM ExamPaper e WHERE e.moduleId.id IN :moduleIds")   
})
public class ExamPaper implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "examPaperId")
    private List<ExamSession> examSessionList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Long id;
    @Size(max = 50)
    @Column(name = "NAME")
    private String name;
    @Size(max = 50)
    @Column(name = "DEPRECATED")
    private String deprecated;
    @Version
    private Integer version;
    @Column(name = "CREATED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Column(name = "CREATED_BY")
    private BigInteger createdBy;
    @Column(name = "MODIFIED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifiedDate;
    @Column(name = "MODIFIED_BY")
    private BigInteger modifiedBy;
    @JoinColumn(name = "MODULE_ID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Module moduleId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "examPaperId")
    private Collection<Section> sectionCollection;
//    @OneToMany(cascade = CascadeType.ALL, mappedBy = "examPaperId")
//    private Collection<ExamSession> examSessionCollection;

    public ExamPaper() {
    }

    public ExamPaper(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDeprecated() {
        return deprecated;
    }

    public void setDeprecated(String deprecated) {
        this.deprecated = deprecated;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public BigInteger getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(BigInteger createdBy) {
        this.createdBy = createdBy;
    }

    public Date getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    public BigInteger getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(BigInteger modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public Module getModuleId() {
        return moduleId;
    }

    public void setModuleId(Module moduleId) {
        this.moduleId = moduleId;
    }

    @XmlTransient
    public Collection<Section> getSectionCollection() {
        return sectionCollection;
    }

    public void setSectionCollection(Collection<Section> sectionCollection) {
        this.sectionCollection = sectionCollection;
    }
//
//    @XmlTransient
//    public Collection<ExamSession> getExamSessionCollection() {
//        return examSessionCollection;
//    }
//
//    public void setExamSessionCollection(Collection<ExamSession> examSessionCollection) {
//        this.examSessionCollection = examSessionCollection;
//    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ExamPaper)) {
            return false;
        }
        ExamPaper other = (ExamPaper) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.iss.examsys.entity.ExamPaper[ id=" + id + " ]";
    }

    @XmlTransient
    public List<ExamSession> getExamSessionList() {
        return examSessionList;
    }

    public void setExamSessionList(List<ExamSession> examSessionList) {
        this.examSessionList = examSessionList;
    }
    
}
